package com.yz.smartpos.yztester.util;

import com.yz.smartpos.yzsmartposapi.IYZSmartPosApi;
import com.yz.smartpos.yztester.ui.MainActivity;
import com.yz.smartpos.yztester.ui.ResultFragment;
import android.app.Activity;
import android.content.res.AssetManager;
import android.util.Log;

import junit.framework.TestCase;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;

import java.util.HashMap;
import java.util.Map;

import static com.yz.smartpos.yztester.util.TesterState.errorCount;


public abstract class ApiTestCase extends TestCase {
    public static Activity mActivity = null;
    public static AssetManager assetManager = null;
    public static IYZSmartPosApi smartPosApi = null;
    public static ResultFragment Logger = ResultFragment.newInstance();

    @Before
    @Override
    public void setUp() throws Exception {
        super.setUp();
    }

    @After
    @Override
    public void tearDown() throws Exception {
        super.tearDown();
    }

    public Activity getActivity() {
        return mActivity;
    }

    public static void setActivity(Activity activity) {
        ApiTestCase.mActivity = activity;
        ApiTestCase.assetManager = activity.getAssets();
        ApiTestCase.smartPosApi = IYZSmartPosApi.get(activity);
    }

    @Override
    public String getName() {
        return super.getName();
    }

    public static void assertTrue(String message, boolean condition)
    {
        try {
            Assert.assertTrue("ERR:"+ message, condition);
            Logger.appendLog(message);
//            Log.i("assert", message);
        } catch (AssertionError e) {
            Logger.appendLog("ERR:"+ message);
            errorCount ++;
            TesterState.mCurrentCase.setErrCount(errorCount);
        }
    }

    public static void fail(String message)
    {
        try {
            Assert.assertTrue("ERR:"+ message, false);
            Logger.appendLog(message);
//            Log.i("assert", message);
        } catch (AssertionError e) {
            Logger.appendLog("ERR:"+ message);
            errorCount ++;
            TesterState.mCurrentCase.setErrCount(errorCount);
        }
    }

    public static void assertTrue_inner(String message, boolean condition)
    {
        try {
            Assert.assertTrue("ERR:"+ message, condition);
            Logger.appendLog_inner(message);
//            Log.i("assert", message);
        } catch (AssertionError e) {
            Logger.appendLog_inner("ERR:"+ message);
            errorCount ++;
            TesterState.mCurrentCase.setErrCount(errorCount);
        }
    }

}
